<?php
/** 
 * @package AMFramework
 * @subpackage Core
 * @author Marcu Alexandru
 * @version 1.0 $Build 305b  
 */
defined('_INDEX') or die('Restricted');

class Amfw_Utils 
{
	public function obImport( $path )
	{	// Gives an E_STRICT notice because its called statically
		// if declared static it gives E_ERROR because 
		// it's not called from object context
		ob_start();
		require_once( $path );
		$content = ob_get_contents();
		ob_end_clean();
	
		return $content;
	}
	
	// Security utility; used for creation of password salts
	public static function md5FromArray( $array, $glue = '' ) {
		return md5(implode($glue, $array));
	}
	
	public static function trim( &$var ) {
		if(is_string( $var )): $var = trim( $var ); endif;
		if(is_array( $var )):
			foreach($var as &$value) {
				self::trim( $value );
			}
		endif;
	}
	
	public static function getPath($class_name,$ds = true)
	{	// O utilizare a autoloaderului pentru a intoarce doar calea catre clasa
		$prefix = substr($class_name, 0, strpos($class_name, '_'));
		
		if(empty($prefix)) return;

		if(_isLib($prefix))
		{
			return $ds ? _aLib($class_name,true) : rtrim(_aLib($class_name,true),DS);
		}
		elseif(_isApp($prefix))
		{
			return $ds ? _aApp($class_name,true) : rtrim(_aApp($class_name,true),DS);
		}
		else
		{
			return $ds ? _aAny($class_name,true) : rtrim(_aAny($class_name,true),DS);
		}
	}
}